home *** CD-ROM | disk | FTP | other *** search
/ PC Play 129 / pc play 129.iso / Demo / man2 / man2.exe / data / scripts / logic_utility_functions.lua < prev    next >
Encoding:
Text File  |  2006-12-19  |  5.3 KB  |  222 lines

  1. function dmCheckForVictory()
  2.     local scenario = GetProperties()
  3.  
  4.     local player = GetPlayerColor()
  5.     local opponent = GetOpponentColor()
  6.     local OurUnits = GetAliveUnitsAmount(player)
  7.     local EnemyUnits = GetAliveUnitsAmount(opponent)
  8.  
  9.     if HasSurrendered(player) then return GAMERESULT_DEFEAT end
  10.     if HasSurrendered(opponent) then return GAMERESULT_VICTORY end
  11.  
  12.     if (OurUnits == 0 and GetTurnNumber(player) > 1) then return GAMERESULT_DEFEAT end
  13.     if (EnemyUnits == 0 and GetTurnNumber(player) > 1) then return GAMERESULT_VICTORY end
  14.  
  15.     local Balance = GetBalance()
  16.     if (Balance <= -100) then return GAMERESULT_DEFEAT end
  17.     if (Balance >= 100 and scenario.iVictoryCondition == 0) then return GAMERESULT_VICTORY end
  18.     return GAMERESULT_NONE
  19. end
  20.  
  21. function dmShowObjectives()
  22.     local scenario = GetProperties()
  23.  
  24.     if scenario.iVictoryCondition == 0 then
  25.         AddObjective("dm_objective")
  26.     else
  27.         AddObjective("dm_objective2")
  28.     end
  29. end
  30.  
  31. ---------------------------------------------------
  32.  
  33. function IsPerished(unit)
  34.     return IsDeployed(unit) and IsDead(unit)
  35. end
  36.  
  37. function WaitForAnimationEnd()
  38.     while ( IsAnyAnimationActive() and IsVisual() ) do
  39.         pause()
  40.     end
  41. end
  42.  
  43. function WaitForCameraMotionEnd()
  44.     while ( IsCameraActive() and IsVisual() ) do
  45.         pause()
  46.     end
  47. end
  48.  
  49. function WaitForSoundEnd(sound_type)
  50.     while( IsSoundActive(sound_type) ) do
  51.         pause()
  52.     end
  53. end
  54.  
  55. function WaitForTypingEnd()
  56.   while ( IsTypingActive() ) do
  57.     pause()
  58.   end
  59. end
  60.  
  61. --------------------------------------------
  62.  
  63. function FinishMOB()
  64.     WaitForCameraMotionEnd()
  65.     WaitForAnimationEnd()
  66.     _FinishMOB()
  67. end
  68.  
  69. function RemoveDead()
  70.     WaitForAnimationEnd()
  71.     _RemoveDead()
  72. end
  73.  
  74. function SetHP(nUnitID, nValue)
  75.     WaitForAnimationEnd()
  76.     _SetHP(nUnitID, nValue)
  77. end
  78.  
  79. function SafePlaySound( audio_fn )
  80.     if DoesFileExist( audio_fn ) then
  81.         PlaySound(audio_fn)
  82.         WaitForSoundEnd(ENET_EFFECT_SOUND_DIRECTSOUND)
  83.     else
  84.         delay(0)
  85.         local error = string.format("sound '%s' not found", audio_fn)
  86.         LogError(error)
  87.     end
  88. end
  89.  
  90. function ShowBallon(nID, nUnitType, nAlignType, hex_x, hex_y, message)
  91.     WaitForCameraMotionEnd()
  92.     ReduceMusicVolume()
  93.     _ShowBallon(nID, nUnitType, nAlignType, hex_x, hex_y, message)
  94.     local audio_fn = string.format("%s.ogg", message)
  95.     SafePlaySound(audio_fn)
  96.     HideBallon(nID)
  97.     RestoreMusicVolume()
  98. end
  99.  
  100. function ShowXBallon(nID, nUnitType, nAlignType, x, y, message)
  101.     ReduceMusicVolume()
  102.     WaitForCameraMotionEnd()
  103.     _ShowXBallon(nID, nUnitType, nAlignType, x, y, message)
  104.     local audio_fn = string.format("%s.ogg", message)
  105.     SafePlaySound(audio_fn)
  106.     HideBallon(nID)
  107.     RestoreMusicVolume()
  108. end
  109.  
  110. function FlyCamera(_11, _12, _13, _14, _21, _22, _23, _24, _31, _32, _33, _34, _41, _42, _43, _44)
  111.     WaitForCameraMotionEnd()
  112.     _FlyCamera(_11, _12, _13, _14, _21, _22, _23, _24, _31, _32, _33, _34, _41, _42, _43, _44)
  113. end
  114.  
  115. function ShowSpeechBallonX(Character, message, audio_fn)
  116.     WaitForCameraMotionEnd()
  117.     ReduceMusicVolume()
  118.     _ShowBallon(-12345, -1, MBS_SPEECH, 1, 1, message)
  119.     AdjustBallon(-12345, 0, 200, 150)
  120.     ShowCharacter(Character.medium, Character.name)
  121.     SafePlaySound(audio_fn)
  122.     HideBallon(-12345)    
  123.     HideCharacters()
  124.     RestoreMusicVolume()
  125. end
  126.  
  127. function SetUnitNameX(uid, Character)
  128.     SetUnitName(uid, Character.name, Character.medium)
  129. end
  130.  
  131. function AddToChatX(nPos, Character, rank)
  132.     AddToChat(nPos, Character.avatar, Character.picture, Character.medium, 7, Character.name)
  133. end
  134.  
  135. function AddRemark(nCharacter, key, audio_fn)
  136.   pause()
  137.   WaitForSoundEnd(ENET_EFFECT_SOUND_DIRECTSOUND)
  138.   WaitForTypingEnd()
  139.   pause(0.5)
  140.   FadeOut(nCharacter)
  141.   while ( IsBigFadeGoing() ) do
  142.     pause()
  143.   end
  144.   _AddRemark(nCharacter, key, audio_fn)
  145.   while ( IsBigFadeGoing() ) do
  146.     pause()
  147.   end
  148.   pause()
  149.   WaitForSoundEnd(ENET_EFFECT_SOUND_DIRECTSOUND)
  150.   RemoveSoundIcon()
  151.   WaitForTypingEnd()
  152. end
  153.  
  154. function FinishBriefing()
  155.   pause(0.1)
  156.   WaitForSoundEnd(ENET_EFFECT_SOUND_DIRECTSOUND)
  157.   WaitForTypingEnd()  
  158. --  _FinishBriefing()
  159. end
  160.  
  161. -- the same as FinishBriefing
  162. function Intro(text, audio)
  163.   pause(0.1)
  164.   WaitForSoundEnd(ENET_EFFECT_SOUND_DIRECTSOUND)
  165.   WaitForTypingEnd()
  166.   _Intro(text, audio)
  167. end
  168.  
  169. function AddToChat(nID, avatar, big_picture, medium_picture, rank, key)
  170.   WaitForTypingEnd()
  171.    _AddToChat(nID, avatar, big_picture, medium_picture, rank, key)
  172.  while (IsFadingActive(nID)) do
  173.     pause()
  174.   end
  175. end
  176.  
  177. function StartBriefing()
  178.     pause(0.1)
  179.     WaitForSoundEnd(ENET_EFFECT_SOUND_DIRECTSOUND)
  180.     WaitForTypingEnd()
  181.     _StartBriefing()
  182.     WaitForSoundEnd(ENET_EFFECT_SOUND_DIRECTSOUND)
  183.     WaitForTypingEnd()
  184.     BriefingConnect()
  185.     WaitForTypingEnd()
  186.     BriefingLogin()
  187. end
  188.  
  189. function SetCapitalModel(nID, nModel)
  190.     _SetCapitalModel(nID, nModel)
  191.     if ( nModel ~= ENET_UNIT_CAPITAL_LARGE and nModel ~= ENET_UNIT_CAPITAL_MEDIUM and nModel ~= ENET_UNIT_CAPITAL_SMALL ) then
  192.         SetAirport( nID, false )
  193.     end
  194. end
  195.  
  196. local old_prompt = ""
  197.  
  198. function ShowPrompting(prompt)
  199.     _ShowPrompting(prompt)
  200.     if prompt ~= old_prompt then
  201.         local audio_fn = string.format("%s.wav", prompt)
  202.         if DoesFileExist( audio_fn ) then
  203.             PlaySound(audio_fn)
  204.         end
  205.         old_prompt = prompt
  206.     end
  207. end
  208.  
  209. function IncorrectAction(message)
  210.     pause()
  211.     stop()
  212.  
  213.     StartMOB(1)
  214.  
  215.     ShowXBallon(51, -1, MBS_CENTER, 300, 300, message)
  216.     
  217.     FinishMOB()
  218.  
  219.     Undo()
  220.  
  221.     old_prompt = ""
  222. end